#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {
    vector<int> roads(n);
    for (int i = 0; i < n; i++)    roads[i] = i + 1;
    vector<int> res;

    int dist = n - 1;
    for (auto& q : queries)
    {
        int k = roads[q[0]];
        roads[q[0]] = q[1];
        while (k != -1 && k < q[1])
        {
            int t = roads[k];
            roads[k] = -1;
            k = t;
            dist--;
        }
        res.push_back(dist);
    }
    return res;
}